FROM tizi-docker-reg.cloudapp.net:5000/ubuntu_nodejs
MAINTAINER Chris Song songchuansheng@91waijiao.com

# install pip
RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get install -y python python-pip python-dev python-mysqldb

# install nginx
RUN apt-get install -y nginx fontconfig

# install mysql server
RUN apt-get install -y mysql-server

# install statsd
RUN npm -g install statsd

# install graphite 
RUN pip install "Twisted<12.0" -i http://mirrors.aliyun.com/pypi/simple/
RUN pip install https://github.com/graphite-project/ceres/tarball/master
RUN pip install "django<1.6" django-tagging flup whisper carbon graphite-web -i http://mirrors.aliyun.com/pypi/simple/
RUN apt-get install -y autoconf automake libtool pkg-config libcairo-dev
RUN cd /tmp; wget http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2; tar jxvf py2cairo-1.10.0.tar.bz2; cd py2cairo-1.10.0; ./waf configure; ./waf build; ./waf install; cd /tmp; rm -rf py2cairo*
RUN ln -s  /usr/local/lib/python2.7/site-packages/cairo/ /usr/local/lib/python2.7/dist-packages/

RUN cp /opt/graphite/conf/carbon.conf.example /opt/graphite/conf/carbon.conf
ADD files/storage-schemas.conf /opt/graphite/conf/storage-schemas.conf
ADD files/statsd.conf /opt/graphite/conf/statsd.conf
ADD files/local_settings.py /opt/graphite/webapp/graphite/local_settings.py

ADD files/Procfile /opt/graphite/Procfile
ADD files/nginx.conf /etc/nginx/nginx.conf
ADD files/nginx-default /etc/nginx/sites-available/default

ADD ./mysql-setup.sh /tmp/mysql-setup.sh
RUN /bin/sh /tmp/mysql-setup.sh

ADD graphite_start.sh /graphite_start.sh

RUN mkdir /.ssh; chmod og-rwx /.ssh
ADD files/authorized_keys /.ssh/authorized_keys
RUN chown root:root /.ssh/authorized_keys

EXPOSE 2003
EXPOSE 2003/udp
EXPOSE 2004
EXPOSE 2004/udp
EXPOSE 3033
EXPOSE 3033/udp
EXPOSE 8125
EXPOSE 8125/udp
EXPOSE 80

VOLUME ["/opt/graphite/storage", "/var/lib/mysql"]

CMD "/graphite_start.sh"

